﻿namespace AI.Graph {


    public abstract class SubNode : CollapsibleNode {

        internal override bool IsValidConnection (ConnectionPort nodePort, ConnectionPort otherPort, out string error) {
            // SubNodes can only connect to the same base.
            // Check if the node of the connection port is the same base.

            State myBase = NodeUtility.FindConnectedNodeOfType<State> (this);

            State otherBase;
            if (otherPort.node.IsState ()) {
                otherBase = (State) otherPort.node;
            }
            else {
                otherBase = NodeUtility.FindConnectedNodeOfType<State> (otherPort.node);
            }

            if (myBase != null && otherBase != null) {
                if (myBase != otherBase) {
                    error = "Sub Node Tree has not the same base State";
                    return false;
                }
            }

            error = "";
            return true;
        }

    }


}